
#ifndef _MEMBER_BTEXTEDIT_H_
#define _MEMBER_BTEXTEDIT_H_

#include <BLine2>
#include <BMap>
#include <BColor>
#include <BRect>
#include <BPoint>
#include <BString>
#include <BRange>
#include <BTextEdit>
#include <BPainter>
#include "ILineBlock.h"
#include "IStack.h"

namespace BWE
{
	class member_BTextEdit : public BObject
	{
		friend class BTextEdit;
	public:
		member_BTextEdit(BTextEdit* textEdit);
		~member_BTextEdit();

		void freshText();
		void emitEdited(BReal time);
		bool freshFormat();

		void resetBlocks();
		void appendBlocks(const BString& str);
		void freshBlocks();
		void freshVisualRange();
		BLine2 inputLine();
		void wrapInputLine();

		BOpera* pushOpera(BOpera::Mode mode, BReal time);
		void operaInput(BReal time, const BCode& code);
		void operaInput(BReal time, const BString& text);
		void operaInsert(BReal time, const BString& text);
		void operaDelete(BReal time);
		void operaRemove(BReal time);

		bool seekPrevWord();
		bool seekNextWord();
		bool seekPrev();
		bool seekNext();
		bool seekUp();
		bool seekDown();
		bool seekHome();
		bool seekEnd();

		bool insertCode(const BCode& code);
		bool insertText(const BString& text);

		bool selectBlocks(int line, int index, int count);
		bool selectBlocks(int min, int max);
		bool selectBlocks();
		bool selectLines();
		void unselect();

		bool removeSelection();

		bool hasSelection() const;
		void selectedRange(BRange& range) const;
		void selectedText(BString& text) const;

		void slotTextFormatDirty(BObject* object, const BValue& value);
		void slotLineFormatDirty(BObject* object, const BValue& value);

	public:
		BTextEdit*			boss;
		BString				text;
		BTextFormatHolder	textFormat;
		bool				wordWrap;
		bool				lineFeed;
		int					lineSpacing;
		int					lineHeight;
		const BStyle*		lineStyle;
		bool				readOnly;
		BReal				blinkTick;
		BReal				blinkTime;
		bool				blinkShown;

		bool				dirty;
		bool				changed;
		bool				editing;
		bool				gotoInput;
		bool				pressed;
		bool				lineSelecting;
		bool				grabSelction;
		ILineBlockList		blocklst;
		ILineBlockIterator	inputBlock;
		ILineBlockIterator	hoverBlock;
		int					hoverIndex;
		ILineBlockIterator	pressBlock;
		int					pressIndex;
		ILineBlockIterator	firstBlock;
		ILineBlockIterator	lastBlock;
		ILineBlockIterator	showBegin;
		ILineBlockIterator	showEnd;

		int						stackSize;
		int						operaIndex;
		IStack<BOperaHolder>	operaStack;
	};
}

#endif